package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.common.mapper.UserInfoMapper;
import com.tanhua.common.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 补全佳人信息的方法 查询mysql
     * @param userId
     * @return
     */
    public UserInfo queryUserInfoByUserId(Long userId) {
        UserInfo userInfo = userInfoMapper.selectById(userId);
        return userInfo;
    }

    /**
     * 从mysql中查询所有佳人详情的方法
     * @param queryWrapper         需要的查询条件当做参数传递过来
     * @return List<UserInfo>
     */
    public List<UserInfo> queryUserInfoList(QueryWrapper queryWrapper) {
        return userInfoMapper.selectList(queryWrapper);

    }

    /**
     * 根据用户们的id 查询mysql数据库 获取详细信息
     * @param userIds
     * @return
     */
    public List<UserInfo> queryUserInfoByUserIdList(Collection<?> userIds) {
        // 创建查询条件
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("user_id",userIds);

        List<UserInfo> userInfoList = userInfoMapper.selectList(queryWrapper);
        return userInfoList;
    }

    /**
     * 跟新用户信息
     * @param userInfo
     * @return
     */
    public Boolean updateUserInfoByUserId(UserInfo userInfo) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userInfo.getUserId());
        return this.userInfoMapper.update(userInfo, queryWrapper) > 0;
    }
}
